package com.yaoxun.bored.service.sys.user;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yaoxun.bored.common.BaseService;
import com.yaoxun.bored.mapper.sys.user.UserMapper;
import com.yaoxun.bored.model.sys.user.User;
import com.yaoxun.bored.model.sys.user.UserQuery;

import tk.mybatis.mapper.entity.Example;


@Service
public class UserService extends BaseService<User> {

	@Inject
	private UserMapper userMapper;
	
	/**
	 * 通过账号查询出用户对象
	 * @author Loren
	 * @createTime 2018年1月31日 下午2:57:19
	 * @param account
	 * @return
	 */
	@Transactional(readOnly = true)
	public User selectOneUser(String account) {
		Example example = new Example(User.class);
		example.createCriteria().andEqualTo("account", account);
		return userMapper.selectOneByExample(example);
	}
	
	@Transactional(readOnly=true)
	public PageInfo<Map<String, Object>> selectByPaging(UserQuery query) {
		PageHelper.startPage(query.getPageInt(), query.getLimitInt(), "user_id");
		List<Map<String,Object>> list = userMapper.selectByPaging();
		PageInfo<Map<String, Object>> info = new PageInfo<>(list);
		return info;
	}
		
}
